/*
雀九当庄模式游戏场景主要逻辑;
*/
var gameData = require("gameData");
var confige = require("confige");
var PaiGowLogic = require("PaiGowLogic");
cc.Class({
    extends: cc.Component,

    properties: {
        isSitting:false,
    },

    onLoad: function () {
        window.clientGlobal.loadingNode.hideLayer();
        this.resNode = this.node.getChildByName("resNode");
        confige.h5RoomID = "0";

        if(cc.sys.platform == cc.sys.IPAD)
            cc.view.setDesignResolutionSize(1280,720,cc.ResolutionPolicy.EXACT_FIT);
        if(cc.sys.platform == cc.sys.MOBILE_BROWSER)
            cc.view.setDesignResolutionSize(1280,790,cc.ResolutionPolicy.EXACT_FIT);
        this.gameBGNode = this.node.getChildByName("gameBgNode").getComponent("gameBgNode");
        this.gameBGNode.onInit();
        if(confige.roomData.roomBankerUid == parseInt(confige.userInfo.playerId) && confige.roomData.roomId == parseInt(confige.userInfo.balcony))
        {
            console.log("isBanker!!!!");
        }else{
            this.node.getChildByName("gameBgNode").getChildByName("mainBg").rotation = 180;
        }
        this.newBetNode = this.node.getChildByName("newBetNode");
        this.gameBGNode.initWithBankerMode(this.newBetNode);

        this.playerNode = this.node.getChildByName("playerNode");
        this.infoNode = this.node.getChildByName("infoNode");
        this.playerLoadOK = false;
        this.infoLoadOK = false;
        this.doLaterLoad = false;
        this.isSanKung = true;
        
        var self = this;
        self.gameInfoNode = self.infoNode.getChildByName("gameInfoNode").getComponent("gameInfoNode");
        self.gameInfoNode.onInit();
        self.gameInfoNode.btn_inviteFriend.active = false;
        self.infoLoadOK = true;
        self.gamePlayerNode = self.playerNode.getChildByName("paiGowPlayerNodeNew").getComponent("gamePlayerNodeNew");
        self.gamePlayerNode.onInit();
        self.doLaterLoad = true;
        self.playerLoadOK = true;
        self.loadRes1();
        // self.loadLater();
        // self.startLater();
        
        console.log("gameScene Load!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    },

    start: function () {

    },
    
    loadLater:function(){
        console.log("loadLater!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        pomelo.clientScene = this;
        confige.curGameScene = this;
        gameData.gameMainScene = this;
        this.gameInfoNode.btn_inviteFriend.active = true;
        this.sceneLoadOver = false;
        this.timeCallFunc = -1;
        this.waitForSettle = false;

        this.winLoseNode = this.node.getChildByName("winLoseNode").getComponent("winLoseNode");
        this.winLoseNode.onInit();
        this.cardMode = confige.roomData.cardMode;
        this.gameMode = confige.roomData.gameMode;
        this.bankerMode = confige.roomData.bankerMode;
        this.betType = {
            "3" : { "1" : true,"5" : true,"10" : true,"15" : true,"20" : true,"repeat" : false,"maxBet" : 20},       //轮庄
            "6" : { "1" : true,"5" : true,"10" : true,"15" : true,"20" : true,"repeat" : false,"maxBet" : 20},       //九点坐庄
            "7" : { "1" : true,"5" : true,"10" : true,"15" : true,"20" : true,"repeat" : true ,"maxBet" : 100},      //无庄（开船）
            "8" : { "1" : true,"2" : true,"3"  : true,"4"  : true,"5"  : true,"repeat" : false,"maxBet" : 5}         //加倍抢庄
        };

        this.time_rob = Math.ceil(confige.roomData.TID_ROB_TIME/1000);
        this.time_betting = Math.ceil(confige.roomData.TID_BETTING/1000);
        this.time_settlement = Math.ceil(confige.roomData.TID_SETTLEMENT/1000);
        
        this.meChair = -1;
        this.curBankerChair = 0;

        this.joinState = confige.roomData.state;
        this.gameBegin = false;     //本房间游戏开始
        this.gameStart = false;     //当前局游戏开始
        this.joinLate = false;
        this.isRoomBanker = false;
        
        this.timerItem = this.node.getChildByName("timerItem").getComponent("timerItem");
        this.timerItem.onInit();

        this.allBetNum = 0;
        this.myBetNum = 0;

        this.initDiceNode();
        this.bottomNode = this.node.getChildByName("bottomNode");
        this.betBtnNode = this.bottomNode.getChildByName("betBtnNode");
        this.btnStandUp = this.bottomNode.getChildByName("btnStandUp");
        this.btnStandUp.getComponent("cc.Button").interactable = false;

        this.mainPlayerNick = this.bottomNode.getChildByName("mainPlayerNode").getChildByName("nick").getComponent("cc.Label");
        this.mainPlayerScore = this.bottomNode.getChildByName("mainPlayerNode").getChildByName("score").getComponent("cc.Label");
        this.mainPlayerHead = this.bottomNode.getChildByName("mainPlayerNode").getChildByName("head").getComponent("cc.Sprite");
        this.mainPlayerNick.string = this.subNameString(confige.userInfo.nickname,6);
        this.mainPlayerScore.string = "0";
        if(confige.meWXHeadFrame != -1)
            this.mainPlayerHead.spriteFrame = confige.meWXHeadFrame;

        if(confige.roomData.roomBankerUid == parseInt(confige.userInfo.playerId) && confige.roomData.roomId == parseInt(confige.userInfo.balcony))
            this.initBankerLayer();
        else
            this.gameInfoNode.btn_quickSay.x = 540

        if(!this.isRoomBanker && !this.isSitting)
            this.gamePlayerNode.showSitBtn();

        this.otherCard = {};
        this.btnOpenCard = this.bottomNode.getChildByName("btnOpenCard");
        this.showCardBtn = this.btnOpenCard.getComponent("cc.Button");
        this.btnMoveCard = this.bottomNode.getChildByName("btnMoveCard");
        this.moveCardBtn = this.btnMoveCard.getComponent("cc.Button");
        this.btnLookOnList = this.node.getChildByName("btnLookonList");
        this.lookOnBtnLabel = this.btnLookOnList.getChildByName("label").getComponent("cc.Label");
        this.deactiveShowCardBtn();
        this.betBtnList = {};
        this.curSelectBet = -1;
        for(var i=0;i<5;i++)
            this.betBtnList[i] = this.betBtnNode.getChildByName("bet"+i).getComponent("cc.Button");
        this.closeBetBtn();
        this.betNumMax = 20;
        this.betNumList = [1,5,10,15,20];
        this.readyBetNum = 1;
        this.betOtherBtnList = {};
        for(var i=0;i<9;i++)
            this.betOtherBtnList[i] = this.node.getChildByName("betNode").getChildByName("betNode"+i);
        this.showOrHideBetOther(0);
        this.gameStatus = this.node.getChildByName("gameStatus");
        this.gameStatusList = {};
        for(var i=1;i<=5;i++)
        {
            this.gameStatusList[i] = this.gameStatus.getChildByName("tips" + i);
        }
        this.sitList = [false,false,false,false,false,false,false,false,false];//9
        //more game info layer
        this.vistorList = {};
        this.userHistoryList = {};
        this.vistorCount = 0;
        for(var i in confige.roomData.spectatorList){
            if(parseInt(confige.roomData.spectatorList[i].uid) == parseInt(confige.userInfo.playerId))
                this.updateMeScore(confige.roomData.spectatorList[i].score);
            if(parseInt(confige.roomData.spectatorList[i].uid) == confige.roomData.roomBankerUid)
                continue;
            this.vistorCount++;
            this.vistorList[parseInt(i)] = confige.roomData.spectatorList[i];
        }
        this.updateLookOnBtnLabel();

        this.smallTips0 = this.node.getChildByName("smallTips0");
        this.smallTips1 = this.node.getChildByName("smallTips1");
        this.smallTips0Label = this.smallTips0.getComponent("cc.Label");
        this.smallTips1Label = this.smallTips1.getComponent("cc.Label");
        this.smallTipsShow0 = false;
        this.smallTipsShow1 = false;

        this.gameHistory = this.node.getChildByName("gameHistory").getComponent("gameHistory");
        this.gameHistory.onInit();
        this.gameScoreList = this.node.getChildByName("gameScoreList").getComponent("gameScoreList");
        this.gameScoreList.onInit();
        this.gamePlayerList = this.node.getChildByName("gamePlayerList").getComponent("gamePlayerList");
        this.gamePlayerList.onInit();
        this.gamePlayerList.parent = this;
        this.lookonList = this.node.getChildByName("lookonList").getComponent("lookonList");
        this.lookonList.onInit();

        this.onMoveCard = false;
        this.moveCardLayer = this.node.getChildByName("moveCardLayer").getComponent("moveCardLayer");
        this.moveCardLayer.onInit("bankerMode");
        this.moveCardLayer.parent = this;

        var curJoinTime = new Date().getTime();
        var bankerName = "——";
        if(confige.roomPlayer[0].playerInfo)
            bankerName = confige.roomPlayer[0].playerInfo.nickname;
        var newRoomData = {roomID:confige.roomData.roomId,bankerID:confige.roomData.roomBankerUid,time:curJoinTime,bankerName:bankerName};
        window.localSetting.addOneRoomHistory(newRoomData);
    },
    //根据长度截取字符串长度 末尾加...
    subNameString:function(str,isLenght){
        var realLength = 0;
        var len = str.length;
        var subLen = 0;
        for (var i = 0; i < len; i++) {
            var charCode = str.charCodeAt(i);
            if (charCode >= 0 && charCode <= 128) 
                realLength += 1;
            else
                realLength += 2;
            subLen += 1;
            if(realLength >= isLenght)
            {
                break;
            }
        }
        var str1 = "";
        if(realLength < len)
        {
            str1 = str.substring(0,subLen)+ "...";
        }
        else
        {
            str1 = str;
        }
        
        return str1;
    },

    startLater: function () {
        this.gamePlayerNode.onStart();
        if(!this.isSitting)
            this.hidePlayerBtn();
        //1002:betting;1003:deal
        for(var i in confige.roomPlayer)
            this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
        if(confige.curReconnectData == -1)  //是否属于重连状态
        {
            if(this.joinState != 1001)
            {
                this.gamePlayerNode.hideSitBtn();
                this.gameBegin = true;
                this.gameStart = true;
                this.joinLate = true;
                this.gameInfoNode.btn_inviteFriend.active = false;
                this.curBankerChair = 0;
                this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setBanker();

                var curBetCount = 0;
                for(var i in confige.roomPlayer)
                {
                    var curChair = confige.getCurChair(i);
                    var chairBet = 0;
                    if(confige.roomData.betList[i] == null)
                        confige.roomData.betList[i] = 0;
                    else{
                        for(var j in confige.roomData.betList[i])
                        {
                            chairBet += confige.roomData.betList[i][j];
                            curBetCount += confige.roomData.betList[i][j];
                        }
                    }
                    
                    this.gamePlayerNode.curBetNumList[curChair] = chairBet;
                    var curChairBet = window.DKTools.cutBetNum(chairBet);
                    for(var j in curChairBet)
                        this.gameBGNode.betItemListAddBetNew(0,curChairBet[j]);
                    if(i != 0 && this.gamePlayerNode.curBetNumList[curChair] != 0)
                        this.gamePlayerNode.playerListNew[curChair].setBet(this.gamePlayerNode.curBetNumList[curChair]);
                }
                this.allBetNum = curBetCount;
                this.showScorePool(this.allBetNum);
                // this.gameBGNode.betItemListAddBetNew(confige.getCurChair(this.curBankerChair),this.allBetNum);
            }else{
                if(this.isSitting)
                    this.btnStandUp.getComponent("cc.Button").interactable = true;
            }
            if(this.joinState == 1002)//betting
            {
                this.gamePlayerNode.cardItemList.createWall();
                if(this.isSitting && !this.isRoomBanker)
                    this.openBetBtn();
            }
            if(this.joinState == 1003)//deal
            {
                if(confige.roomData.dice1 && confige.roomData.dice2)
                    this.showDiceActionOnReconnect(confige.roomData.dice1,confige.roomData.dice2);
                for(var i in confige.roomPlayer)
                {
                    this.gamePlayerNode.playerCardList[i] = confige.roomData.player[i].handCard;
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].initCardWithBack();
                    if(this.isSitting && !confige.roomPlayer[this.meChair].isShowCard)
                        this.activeShowCardBtn();
                    else
                        this.deactiveShowCardBtn();
                }
            }
        }else{
            this.recoverGame();
            confige.curReconnectData = -1;
        }
        console.log("roomId + meChair === " + (confige.roomData.roomId*10 + this.meChair));
        

        this.sceneLoadOver = true;
        
        //处理缓存的服务器消息
        confige.gameSceneLoadOver = true;
        confige.curSceneIndex = 2;
        var infoCount = confige.gameSceneLoadData.length;
        console.log(confige.gameSceneLoadData);
        for(var i=0;i<infoCount;i++)
        {
            console.log("deal once!!!!!!!!");
            var curInfo = confige.gameSceneLoadData.shift();
            pomelo.dealWithOnMessage(curInfo);
            console.log(curInfo);
        }
        confige.gameSceneLoadData = [];
        console.log(confige.gameSceneLoadData);
    },

    setBanker:function(chair){
        this.curBankerChair = chair;
    },

    showScorePool:function(score,type,bankerScore,change){
        console.log("show fuck score pool!!!!!!");
        this.gameBGNode.scorePool.active = true;
        this.gameBGNode.scorePoolLabel.string = "总下注" + score + "分";
        this.gameBGNode.scorePoolNum = parseInt(score);

        if(bankerScore)
        {
            console.log("curChair === " + this.curBankerChair + "newChiar===" + confige.getCurChair(this.curBankerChair));
            this.gamePlayerNode.playerScoreList[this.curBankerChair] = bankerScore;
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setScore(this.gamePlayerNode.playerScoreList[this.curBankerChair]);
        }
        if(change === true)
        {
            // this.gameBGNode.betItemRemoveToBanker(confige.getCurChair(this.curBankerChair));
            var callFunc = function(){
                this.gameBGNode.betItemListClean();
                console.log("fuck you scorePool 丢钱出去！！！！！！！！！！！！！！")
                this.gameBGNode.betItemListAddBetNew(confige.getCurChair(this.curBankerChair),callFunc.score);
            };
            callFunc.score = score;
            this.scheduleOnce(callFunc,1);
        }
    },

    showGameStatus:function(index){
        this.gameStatus.active = true;
        for(var i=1;i<=5;i++)
            this.gameStatusList[i].active = false;
        this.gameStatusList[index].active = true;
    },

    hideGameStatus:function(){
        this.gameStatus.active = false;
    },

    addBet:function(betNum, chair){
        this.gameBGNode.betItemListAddBetNew(chair,betNum);
        this.allBetNum = this.allBetNum + betNum;
        if(chair == 0)
            this.myBetNum = this.myBetNum + betNum;
        if(this.gameMode != 3)
            this.showScorePool(this.allBetNum,1);
        this.gamePlayerNode.curBetNumList[chair] += betNum;
        this.gamePlayerNode.playerListNew[chair].setBet(this.gamePlayerNode.curBetNumList[chair]);
        if(confige.soundEnable == true)
            confige.playSoundByName("sendBet");
    },

    addBetNew:function(betNum, beginChair,endChair){
        var isMe = 0;
        if(beginChair == this.meChair)
            isMe = 1;
        this.gameBGNode.betItemListAddBetNew(beginChair,betNum);
        // this.gameBGNode.betItemListAddBetNew(oriChair,betNum);
        this.allBetNum = this.allBetNum + betNum;
        // if(oriChair == this.meChair)
            // this.myBetNum = this.myBetNum + betNum;
        if(this.gameMode != 3)
            this.showScorePool(this.allBetNum,1);
        this.gamePlayerNode.curBetNumList[endChair] += betNum;
        this.gamePlayerNode.playerListNew[endChair].setBet(this.gamePlayerNode.curBetNumList[endChair]);
        if(confige.soundEnable == true)
            confige.playSoundByName("sendBet");
    },
    
    onBtnBetClicked:function(event, customEventData){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var betType = parseInt(customEventData);
        var curBetNum = this.betNumList[betType];
        if(this.curSelectBet == betType){
            this.showOrHideBetOther(0);
            return;
        }
        if(this.curSelectBet >= 0)
            this.betBtnList[this.curSelectBet].node.y = 0;
        this.curSelectBet = betType;
        this.betBtnList[betType].node.y = 30;
        this.readyBetNum = curBetNum;
        this.showOrHideBetOther(1);
    },

    statusChange:function(index){
        if(index === 1)
            this.timerItem.setTime(this.time_betting);
        else if(index === 2)
            this.timerItem.setTime(this.time_settlement-8);
    },
    
    onServerReady:function(chair){
        return;
        //this mode don`t use this function;
    },

    onBtnReadyClicked:function(){
        this.gameInfoNode.btn_inviteFriend.active = true;
        window.DKTools.audioEG.playEffect("tips_btnClick");
        this.cleanDice();
        if(this.gameInfoNode.settleLayerLoad != -1 && this.gameInfoNode.settleLayer.onShow == true){
            this.gameInfoNode.settleLayer.hideNoClick();
            if(this.isZhajinniu)
            {
                for(var i=0;i<confige.playerMax;i++)
                {
                    this.lookCardList[i] = false;
                    this.giveUpList[i] = false;
                    this.loseList[i] = false;
                    this.loseNodeList[i].active = false;
                }
            }
            this.deactiveShowCardBtn();
            this.gameBGNode.betItemListClean();
            this.gameBGNode.scorePool.active = false;

            for(var i in confige.roomPlayer)
            {
                var curChair = confige.getCurChair(i);
                this.gamePlayerNode.playerListNew[curChair].resetCard();
                this.gamePlayerNode.playerListNew[curChair].hideBanker();
                this.gamePlayerNode.playerListNew[curChair].setBet(0);
                this.gamePlayerNode.curBetNumList[curChair] = 0;
            }
            // this.gamePlayerNode.playerListNew[9].resetCard();
        }
        if(this.isRoomBanker)
            this.btnDealCard.getComponent("cc.Button").interactable = true;
        //this mode don`t use this function;
    },

    onServerBeginBetting:function(data){
        // this.gamePlayerNode.playerList[9].active = false;
        if(confige.curSex == 2)
            window.DKTools.audioEG.playEffect("tips_beginBet0");
        else
            window.DKTools.audioEG.playEffect("tips_beginBet1");
        var bankerChair = data.banker;
        this.allBetNum = 0;
        this.myBetNum = 0;
        this.statusChange(1);
        this.curBankerChair = bankerChair;
        if(bankerChair == this.meChair){
            this.showGameStatus(4);
        }else{
            this.openBetBtn();
            this.showGameStatus(2);
        }
        if(confige.roomData.gameMode != 3)
            this.showScorePool(this.allBetNum);
        for(var i in confige.roomPlayer)
            this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideBanker();
        if(bankerChair != -1)
            this.gamePlayerNode.playerListNew[confige.getCurChair(bankerChair)].setBanker();

            if(this.joinState == 1005 &&  this.cardMode == 2)
            {
                for(var i in confige.roomPlayer)
                {
                    if(confige.roomPlayer[i].isActive == true)// && confige.roomPlayer[i].isReady == true)
                    {
                        var curChair = confige.getCurChair(i);
                        if(curChair != 0)
                            this.playerListNew[curChair].showCardBackWithCount(2);
                    }
                }
            }
    },

    onServerDealCard:function(data){
        this.showDiceAction(data.dice1,data.dice2);
        var handCards = data.handCards;
        this.otherCard = data.surplusCards;
        // this.gamePlayerNode.playerList[9].active = true;
        this.closeBetBtn();
        this.showOrHideBetOther(0);
        this.hideGameStatus();
        for(var i in handCards)
        {
            if(handCards.hasOwnProperty(i))
            {
                this.gamePlayerNode.playerCardList[i] = handCards[i];
            }
        }
        this.statusChange(2);
        this.timerItem.hideTimer();

        var callFuncDeal = function(){
            console.log("dice count ===== "+(data.dice1+data.dice2));
            var beginChair = (data.dice1+data.dice2)%10;
            if(beginChair == 9)
                beginChair = 0;
            var str = "tips_beginChair_" + beginChair
            window.DKTools.audioEG.playEffect(str);
            this.gamePlayerNode.cardItemList.dealCardWithType(0,beginChair);
            
        };
        this.scheduleOnce(callFuncDeal,2);
    },

    dealCardOverCall:function(){
        // var callFunc2 = function(){
        //     console.log("显示中间明牌");
        //     for(var j=0;j<2;j++)
        //     {
        //         var index = parseInt(j);
        //         this.gamePlayerNode.playerListNew[9].setCardWithIndex(index, callFunc2.curCardData[index].num, callFunc2.curCardData[index].type);
        //     }
        // };
        // callFunc2.curCardData = this.otherCard;
        // this.scheduleOnce(callFunc2,1);
        this.timerItem.showTimer();
        var callFunc3 = function(){
            this.activeShowCardBtn();
        };
        this.scheduleOnce(callFunc3,1);
    },

    activeShowCardBtn:function(){
        this.showCardBtn.interactable = true;
        this.moveCardBtn.interactable = true;
    },

    deactiveShowCardBtn:function(){
        this.showCardBtn.interactable = false;
        this.moveCardBtn.interactable = false;
    },

    btn_showMyCard:function(event,customEventData){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var index = parseInt(customEventData);
        if(index)
        {
            this.onMoveCard = true;
            var handCard = this.gamePlayerNode.playerCardList[this.meChair];
            this.moveCardLayer.showLayerB(handCard);
        }else{
            pomelo.clientSend("showCard");
            this.deactiveShowCardBtn();
            var handCard = this.gamePlayerNode.playerCardList[this.meChair];
            var curNiuType = 0;
            curNiuType = PaiGowLogic.getType(handCard);
            var isShowB = false;
            if(curNiuType.type >= 1 && curNiuType.type <=9 && curNiuType.card.num == 10)
                isShowB = true;
            this.gamePlayerNode.playerListNew[this.meChair].showCardType(curNiuType.type,isShowB);
        }
    },
    
    btnShowCardOnMove:function(){
        this.onMoveCard = false;
        pomelo.clientSend("showCard");
        this.deactiveShowCardBtn();
        this.moveCardLayer.hideLayerB();

        var handCard = this.gamePlayerNode.playerCardList[this.meChair];
        var curNiuType = 0;
        curNiuType = PaiGowLogic.getType(handCard);
        var isShowB = false;
            if(curNiuType.type >= 1 && curNiuType.type <=9 && curNiuType.card.num == 10)
                isShowB = true;
        this.gamePlayerNode.playerListNew[this.meChair].showCardType(curNiuType.type,isShowB);
    },

    showMingCard:function(cards){
        var cardsCount = 0;
        for(var i in confige.roomPlayer)
        {
            if(confige.roomPlayer[i].isActive == true)// && confige.roomPlayer[i].isReady == true)
            {
                var curChair = confige.getCurChair(i);
            }
        }
        for(var i in cards)
        {
            cardsCount ++;
        }
        
        this.newDisCard(cardsCount);

        var callFunc = function(){
            for(var i in callFunc.cards)
            {
                this.gamePlayerNode.playerListNew[0].setCardWithIndex(i, callFunc.cards[i].num, callFunc.cards[i].type);
            }
        };
        callFunc.cards = cards;
        this.scheduleOnce(callFunc,0.5);
    },

    onServerSettlement:function(data){
        if(this.onMoveCard)
        {
            this.onMoveCard = false;
            this.moveCardLayer.btnShowCardClickB();
        }
        this.hideOpenCard(1);
        this.hideOpenCard(2);
        this.hideGameStatus();

        this.statusChange(0);
        //第一步显示玩家手牌
        for(var i in data.result)
        {
            if(data.result.hasOwnProperty(i))
            {
                this.gamePlayerNode.showOneCard(i);
                if(parseInt(data.player[i].uid) == parseInt(confige.userInfo.playerId))
                {
                    if(data.curScores[i] >= 0)
                        this.winLoseNode.showLayer(true);
                    else
                        this.winLoseNode.showLayer(false);
                }
            }
        }
        this.waitForSettle = true;
        this.deactiveShowCardBtn();
        this.gameStart = false;
        this.joinLate = false;
        this.gameInfoNode.btn_close.interactable = true;
        this.timerItem.hideTimer();

        for(var i in confige.roomPlayer)
            if(confige.roomPlayer[i].isActive == true)            
                confige.roomPlayer[i].isReady = false;

        //分割筹码
            console.log("this.curBankerChair111==="+this.curBankerChair);
            console.log("this.curBankerChair222==="+confige.getCurChair(this.curBankerChair));
            this.gameBGNode.betItemRemoveToBanker(confige.getCurChair(this.curBankerChair));
            if(confige.soundEnable == true)
                confige.playSoundByName("getBet");
            var sendBetFunc = function(){
                var newScoreList = {};
                for(var i in data.resultState)
                {
                    var betCount = 0;
                    for(var j in data.betList[i])
                        betCount += data.betList[i][j];
                    var newScore = betCount * this.getScoreType(data.resultState[i]);
                    newScoreList[i] = newScore;
                }
                
                this.gameBGNode.betItemSendFromBankerNew(newScoreList,confige.getCurChair(this.curBankerChair));
                if(confige.soundEnable == true)
                    confige.playSoundByName("getBet");
            };

            this.scheduleOnce(sendBetFunc,2.25);

        //第二步延迟显示结算界面
        var self = this;
        var showSettleFunc1 = function(){
            self.gameInfoNode.settleLayer.show(data.curScores[self.meChair]);
            var newMyScore = null;
            var myScoreCount = 0;
            var newSitScore = 0;
            for(var i in data.result)
            {
                if(data.result.hasOwnProperty(i))
                {
                    if(i != 0)
                    {
                        if(data.betList[i][self.meChair] == null)
                            newMyScore = 0;
                        else
                            newMyScore = data.betList[i][self.meChair]*self.getScoreType(data.resultState[i]);
                        myScoreCount += newMyScore;
                        var betCount = 0;
                        for(var j in data.betList[i])
                            betCount += data.betList[i][j];
                        newSitScore = betCount * self.getScoreType(data.resultState[i]);
                    }else{
                        newSitScore = data.curScores[0];
                    }
                    var niuType = data.result[i].type;
                    var curSitWin = self.getScoreType(data.resultState[i]);
                    if(data.player[i].isActive == true){
                        self.gameInfoNode.settleLayer.addOneSettle(confige.roomData.player[i].playerInfo.nickname, niuType, newSitScore,2,data.player[i].handCard,i,newMyScore,data.result[i].card.num,curSitWin);
                        self.gamePlayerNode.playerScoreList[i] = data.realScores[i];
                        self.gamePlayerNode.playerListNew[confige.getCurChair(i)].setScore(self.gamePlayerNode.playerScoreList[i]);
                        if(i == self.meChair)
                            self.updateMeScore(data.realScores[i]);
                    }
                    else{
                        
                        self.gameInfoNode.settleLayer.addOneSettle("空闲", niuType, newSitScore,2,data.player[i].handCard,i,newMyScore,data.result[i].card.num,curSitWin);
                    }
                }
            }
            if(self.meChair == 0)
                myScoreCount = data.curScores[0];
            self.gameInfoNode.settleLayer.showMyScore(myScoreCount);

            self.waitForSettle = false;

            if(!self.isRoomBanker){
                if(!self.isSitting)
                    self.gamePlayerNode.showSitBtn();
                if(self.isSitting)
                    self.btnStandUp.getComponent("cc.Button").interactable = true;
            }

            self.resetSceneNew();
        };
        
        var showSettleFunc2 = function(){
            if(this.gameInfoNode.settleLayer == -1){
                cc.loader.loadRes("prefabs/game/settleLayerBankerMode", cc.Prefab, function (err, prefabs) {
                    var newLayer = cc.instantiate(prefabs);
                    self.gameInfoNode.layerNode1.addChild(newLayer,10);
                    self.gameInfoNode.settleLayer = newLayer.getComponent("settleLayer");
                    self.gameInfoNode.settleLayer.showLayer();
                    self.gameInfoNode.settleLayer.parent = self;
                    showSettleFunc1();
                });
            }else{
                self.gameInfoNode.settleLayer.showLayer();
                showSettleFunc1();
            }
        };
        this.scheduleOnce(showSettleFunc2,5);
    },

    resetScene:function(){
        this.deactiveShowCardBtn();
        this.timerItem.active = false;
    },

    //根据重连数据重现游戏状态
    recoverGame:function(){
        this.onReConnect = true;
        if(confige.curReconnectData.state == 1100){
            gameData.gameInfoNode.btn_continue.active = true;
            this.gameInfoNode.btn_inviteFriend.active = false;
            return;
        }
        console.log("处理重连数据");

        if(confige.curReconnectData.freeState && confige.curReconnectData.freeState != false)
            this.gameInfoNode.onServerShowFinish(confige.curReconnectData.freeState);
        console.log("on recoverGame() !!!!!!!!!!!!!");
        this.gameInfoNode.roomMaxTime = confige.curReconnectData.roomInfo.maxGameNumber;
        //重置场景
        this.resetScene();
        console.log(confige.roomPlayer);
        for(var i in confige.roomPlayer)
        {
            this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
            if(confige.roomPlayer[i].isActive)
            {
                this.gamePlayerNode.addOnePlayer(confige.roomPlayer[i]);
                this.gamePlayerNode.playerScoreList[i] = confige.curReconnectData.roomInfo.player[i].score;
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setScore(this.gamePlayerNode.playerScoreList[i]);
                if(parseInt(confige.roomPlayer[i].uid) == parseInt(confige.userInfo.playerId))
                    this.updateMeScore(confige.roomPlayer[i].score);
                if(!confige.roomPlayer[i].isOnline)
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setLeave();
                else
                    this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideLeave();
            }
            if(confige.roomPlayer[i].isActive && !confige.roomPlayer[i].isOnline)
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].setLeave();
            else
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideLeave();
        }
        //重现下注金额
        this.gameInfoNode.roomCurTime = confige.curReconnectData.roomInfo.gameNumber;
        this.gameInfoNode.roomTime.string = "第" + this.gameInfoNode.roomCurTime + "/" + this.gameInfoNode.roomMaxTime + "局";
        if(confige.curReconnectData.state != 1001)
        {
            this.gameBegin = true;
            this.gameStart = true;
            this.joinLate = true;
            this.gameInfoNode.btn_inviteFriend.active = false;
            this.curBankerChair = 0;
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.curBankerChair)].setBanker();

            var curBetCount = 0;
            for(var i in confige.roomPlayer)
            {
                var curChair = confige.getCurChair(i);
                var chairBet = 0;
                if(confige.curReconnectData.betList[i] == null)
                    confige.curReconnectData.betList[i] = 0;
                else{
                    for(var j in confige.curReconnectData.betList[i])
                    {
                        chairBet += confige.curReconnectData.betList[i][j];
                        curBetCount += confige.curReconnectData.betList[i][j];
                    }
                }
                    
                this.gamePlayerNode.curBetNumList[curChair] = chairBet;
                var curChairBet = window.DKTools.cutBetNum(chairBet);
                for(var j in curChairBet)
                    this.gameBGNode.betItemListAddBetNew(0,curChairBet[j]);
                if(i != 0 && this.gamePlayerNode.curBetNumList[curChair] != 0)
                    this.gamePlayerNode.playerListNew[curChair].setBet(this.gamePlayerNode.curBetNumList[curChair]);
            }
            this.allBetNum = curBetCount;
            this.showScorePool(this.allBetNum);
            // this.gameBGNode.betItemListAddBetNew(confige.getCurChair(this.curBankerChair),this.allBetNum);
        }else{
            if(this.isSitting)
                this.btnStandUp.getComponent("cc.Button").interactable = true;
        }
        if(confige.curReconnectData.state == 1002)//betting
        {
            this.gamePlayerNode.cardItemList.createWall();
            if(this.isSitting && !this.isRoomBanker)
                this.openBetBtn();
        }
        if(confige.curReconnectData.state == 1003)//deal
        {
            if(confige.roomData.dice1 && confige.roomData.dice2)
                this.showDiceActionOnReconnect(confige.roomData.dice1,confige.roomData.dice2);
            for(var i in confige.roomPlayer)
            {
                this.gamePlayerNode.playerCardList[i] = confige.roomData.player[i].handCard;
                this.gamePlayerNode.playerListNew[confige.getCurChair(i)].initCardWithBack();
                if(confige.roomPlayer[i].isShowCard == true)
                    this.gamePlayerNode.showOneCard(i);
            }
            if(this.isSitting && !confige.roomPlayer[this.meChair].isShowCard)
                this.activeShowCardBtn();
            else
                this.deactiveShowCardBtn();
        }

        if(this.gameInfoNode.roomCurTime != 0)
        {
            this.gameBegin = true;
        }
        confige.curReconnectData = -1;
    },

    connectCallBack:function(){

    },

    onNewGameStart:function(){
        this.onBtnReadyClicked();

        this.gamePlayerNode.cardItemList.createWall();
        if(!this.isRoomBanker){
            this.gamePlayerNode.hideSitBtn();
            this.btnStandUp.getComponent("cc.Button").interactable = false;
        }
        if(confige.roomPlayer[this.meChair] && confige.roomPlayer[this.meChair].isReady == false)
            this.joinLate = true;

        for(var i in confige.roomPlayer)
        {
            this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
            this.gamePlayerNode.playerListNew[confige.getCurChair(i)].hideBanker();
        }
        this.gameBegin = true;
        this.gameStart = true;
        this.meGiveUp = false;
        this.newResetCard();
        for(var i=0;i<confige.playerMax;i++)
        {
            this.gamePlayerNode.playerListNew[i].hideReady();
        }
        this.gameInfoNode.btn_inviteFriend.active = false;
        this.gamePlayerNode.playerCount = this.gamePlayerNode.newPlayerCount;
        this.gamePlayerNode.noShowCardCount = this.gamePlayerNode.playerCount;
        if(confige.roomData.gameMode != 3)
            this.showScorePool(0);
    },

    onNewGameBegin:function(data){
        this.gameStart = true;
        this.gamePlayerNode.playerCount = this.gamePlayerNode.newPlayerCount;
        this.allBetNum = 0;
        this.showScorePool(this.allBetNum);
    },

    update: function (dt) {
        window.GVoice.gvoicePoll();
    },

    newDisCard:function(times){
        if(times == 1)
            this.gamePlayerNode.cardItemList.disCardOneRound();
        else
            this.gamePlayerNode.cardItemList.disCardWithRoundTime(times);
    },

    newResetCard:function(){
        this.gamePlayerNode.cardItemList.resetCardList();
        for(var i in confige.roomPlayer)
            if(confige.roomPlayer[i].isActive == true)
                this.gamePlayerNode.cardItemList.activePlayer(confige.getCurChair(i));
    },

    showOpenCard:function(index){
        return;
    },

    hideOpenCard:function(index){
        return;
    },

    btnOpenCard:function(event,customEventData){
        var index = parseInt(customEventData);
        if(index == 1)
        {
            this.hideOpenCard(1);
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.meChair)].setCardWithIndex(1, this.gamePlayerNode.playerCardList[this.meChair][1].num, this.gamePlayerNode.playerCardList[this.meChair][1].type);
        }else if(index == 2){
            this.hideOpenCard(2);
            this.gamePlayerNode.playerListNew[confige.getCurChair(this.meChair)].setCardWithIndex(2, this.gamePlayerNode.playerCardList[this.meChair][2].num, this.gamePlayerNode.playerCardList[this.meChair][2].type);
        }
    },

    openShare:function(){
        if(confige.curOverLayer != -1)
            confige.curOverLayer.openShare();
    },

    WXCancle:function(){
        if(confige.curOverLayer != -1)
            confige.curOverLayer.openShare();
    },

    showReConnect:function(){
        gameData.gameInfoNode.showReConnect();
        console.log("showReConnect!!!!!!!!!");
    },

    hideReConnect:function(){
        gameData.gameInfoNode.hideReConnect();
        console.log("hideReConnect!!!!!!!!!");
    },

    sayWithID:function(voiceID){
        pomelo.clientSend("say",{"msg": {"sayType":255, "id": voiceID, "time": this.gameInfoNode.sayTime}});
    },

    readyBegin:function(time){
        this.timerItem.setTime(parseInt(time/1000)); 
    },

    loadRes1:function(){
        var self = this;
        var onLoadNext = false;
        var loadCard = false;
        var loadNiutype = false;
        //cardFrame
        cc.loader.loadRes("prefabs/game/cardNode", cc.Prefab, function (err, prefabs) {
            var newNode = cc.instantiate(prefabs);
            self.resNode.addChild(newNode);
            confige.paiGowCardFrameMap[0] = newNode.getChildByName("card10").getComponent("cc.Sprite").spriteFrame;
            for(var i=1;i<=10;i++)
            {
                confige.paiGowCardFrameMap[i] = newNode.getChildByName("card"+i).getComponent("cc.Sprite").spriteFrame;
            }
            loadCard = true;
            if(loadCard == true && loadNiutype == true)
            {
                if(onLoadNext == false)
                {
                    onLoadNext = true;
                    self.loadLater();
                    self.startLater();
                    self.loadRes2();
                    self.initAudio();
                }
            }
        });
        
        
        //niutypeFrame
        cc.loader.loadRes("prefabs/game/typeNode", cc.Prefab, function (err, prefabs) {
            var newNode = cc.instantiate(prefabs);
            self.resNode.addChild(newNode);
            for(var i=0;i<=10;i++)
            {
                var spriteFrame = newNode.getChildByName("type"+i).getComponent("cc.Sprite").spriteFrame;
                confige.paiGowTypeFrameMap[i] = spriteFrame;
            }
            for(var i=1;i<=9;i++)
                confige.paiGowTypeFrameMapB[i] = newNode.getChildByName("type"+i+"B").getComponent("cc.Sprite").spriteFrame;
            loadNiutype = true;
            if(loadCard == true && loadNiutype == true)
            {
                if(onLoadNext == false)
                {
                    onLoadNext = true;
                    self.loadLater();
                    self.startLater();
                    self.loadRes2();
                    self.initAudio();
                }
            }
        });
    },

    loadRes2:function(){
        var self = this;
        //faceAni
        cc.loader.loadRes("prefabs/game/faceAniNode", cc.Prefab, function (err, prefabs) {
            var newNode = cc.instantiate(prefabs);
            self.resNode.addChild(newNode);
            for(var i=1;i<=6;i++)
                confige.faceAniMap[i] = newNode.getChildByName("faceAni"+i);
            confige.loadFaceAni = true;
        });
    },

    initAudio:function(){
        for(var i=0;i<=20;i++)
        {
            cc.loader.loadRes("sound/cardType/0/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "female_" + "type_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/1/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "male_" + "type_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/2/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "banker_" + "type_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }
        for(var i=1;i<=9;i++)
        {
            cc.loader.loadRes("sound/cardType/0/"+i+"B",function(index){
                return  function (err, audio) {
                    var curIndex = "female_" + "type_" + index + "B";
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/1/"+i+"B",function(index){
                return  function (err, audio) {
                    var curIndex = "male_" + "type_" + index + "B";
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/cardType/2/"+i+"B",function(index){
                return  function (err, audio) {
                    var curIndex = "banker_" + "type_" + index + "B";
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }

        for(var i=1;i<=6;i++)
        {
            cc.loader.loadRes("sound/face/F_" + (i),function(index){
                return  function (err, audio) {
                    var curIndex = "female_" + "face_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/face/M_" + (i),function(index){
                return  function (err, audio) {
                    var curIndex = "male_" + "face_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }
        for(var i=1;i<=7;i++)
        {
            cc.loader.loadRes("sound/face/" + (i),function(index){
                return  function (err, audio) {
                    var curIndex = "face_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }

        for(var i=1;i<=17;i++)
        {
            cc.loader.loadRes("sound/chat/0/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "female_chat_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));

            cc.loader.loadRes("sound/chat/1/" + i,function(index){
                return  function (err, audio) {
                    var curIndex = "male_chat_" + index;
                    window.DKTools.audioEG.audioList[curIndex] = audio;
                }
            }(i));
        }
    },

    closeBetBtn:function(){
        for(var i=0;i<5;i++)
            this.betBtnList[i].interactable = false;
    },

    openBetBtn:function(){
        for(var i=0;i<5;i++)
            this.betBtnList[i].interactable = true;
    },

    btnStandUpClick:function(){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        console.log("btnStandUp!!!!!");
        pomelo.request("connector.entryHandler.sendData", {"code":"standUp","params":{}}, function(data) {
            console.log("standUp @@@@@@@@");
            console.log(data);
        });
    },

    btnBankerStart:function(){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var self = this;
        pomelo.request("connector.entryHandler.sendData", {"code":"houseOwnerCmd","params":{code:"beginGame"}}, function(data) {
            console.log("beginGame @@@@@@@@");
            console.log(data);
            if(data.flag)
                self.btnDealCard.getComponent("cc.Button").interactable = false;
            if(data.flag == "notDiamond"){
                self.getDiamond();
            }
        });
    },
    resumeBankerStart:function(){
        if(!this.gameStart)
            this.btnDealCard.getComponent("cc.Button").interactable = true;
    },

    initBankerLayer:function(){
        this.isRoomBanker = true;
        this.btnStandUp.active = false;
        this.betBtnNode.active = false;
        this.btnDealCard = this.bottomNode.getChildByName("btnDealCard");
        this.btnDealCard.active = true;
        this.btnPlayerList = this.bottomNode.getChildByName("btnPlayerList");
        this.btnPlayerList.active = true;
        this.btnAddGameTime = this.bottomNode.getChildByName("btnAddGameTime");
        this.btnAddGameTime.active = true;
        this.addGameTimeLayer = this.node.getChildByName("addGameTimeLayer").getComponent("addGameTimeLayer");
        this.addGameTimeLayer.onInit(confige.roomData.roomId);

        this.btnSetKill = this.node.getChildByName("btnSetKill");
        this.btnSetKill.active = true;
        this.setKillNode = this.node.getChildByName("setKillNode");
        this.setKillPoint = this.setKillNode.getChildByName("pointEdit").getComponent("cc.EditBox");
        this.curKillPoint = confige.roomData.killPoints;

        // this.node.getChildByName("diaLabel").active = true;
        // this.node.getChildByName("btnDiaAdd").active = true;
        // this.node.getChildByName("btnDiaCheck").active = true;
        // this.diaLabel = this.node.getChildByName("diaLabel").getComponent("cc.Label");
        // this.diaLabel.string = "";
    },

    serverSitDown:function(data){
        if(data.uid == confige.userInfo.playerId){
            this.btnStandUp.getComponent("cc.Button").interactable = true;
            this.isSitting = true;
            this.showPlayerBtn();
        }
        delete this.vistorList[parseInt(data.player.uid)];
        this.gamePlayerNode.addOnePlayer(data.player);
        var curNickName = data.player.playerInfo.nickname;
        var curChair = data.chair;
        if(curChair == 0)
            curChair = 9;
        this.showSmallTips("玩家"+curNickName+"坐在了"+curChair+"号位置!");
        this.updateLookOnBtnLabel();
    },

    serverStandUp:function(data){
        if(data.uid == confige.userInfo.playerId){
            this.btnStandUp.getComponent("cc.Button").interactable = false;
            this.isSitting = true;
            this.hidePlayerBtn();
        }
        this.gamePlayerNode.playerQuit(data.chair,false);
        var curNickName = data.info.playerInfo.nickname;
        var curChair = data.chair;
        if(curChair == 0)
            curChair = 9;
        this.showSmallTips("玩家"+curNickName+"离开了"+curChair+"号位置!");
    },

    serverChangeScore:function(data){
        // cmd: "managerChangeScore", uid: 10019, score: 100, curScore: 900, chair: 1
        console.log("fuck showChangeScore!!!!!!");
        if(parseInt(data.uid) == confige.userInfo.playerId)
            this.updateMeScore(data.curScore);
        if(data.chair)
            this.gamePlayerNode.playerListNew[data.chair].setScore(data.curScore);
    },
    //游客的加入和离开
    serverVistorJoinOrLeave:function(data,type){
        if(parseInt(data.uid) == confige.roomData.roomBankerUid)
            return;
        if(type)//JOIN
        {
            this.vistorList[parseInt(data.uid)] = data.info;
            var newHistoryData = {head:data.info.playerInfo.head,nickname:data.info.playerInfo.nickname}
            this.userHistoryList[parseInt(data.uid)] = newHistoryData;
        }else{//LEAVE
            // this.vistorList[parseInt(data.uid)] = null;
            var curNickName = this.vistorList[parseInt(data.uid)].playerInfo.nickname;
            this.showSmallTips("玩家"+curNickName+"离开了游戏!");
            delete this.vistorList[parseInt(data.uid)];
        }
        if(data.uid == confige.userInfo.playerId)
            this.updateMeScore(data.info.score);

        this.updateLookOnBtnLabel();
        console.log("vistorList ===== ");
        console.log(this.vistorList);
    },

    updateLookOnBtnLabel:function(){
        var curVistorCount = 0;
        for(var i in this.vistorList)
            curVistorCount ++;
        this.lookOnBtnLabel.string = "当前旁观人数:"+curVistorCount;
    },

    addOnePlayer:function(data){
        var curNickName = data.info.playerInfo.nickname;
        this.showSmallTips("玩家"+curNickName+"加入了游戏!");
    },

    btnShowGameHistory:function(){
        var self = this;
        pomelo.request("connector.entryHandler.sendData", {"code":"getGameSettlementRecord","params":{}}, function(data) {
            console.log("获取房间流水记录");
            console.log(data);
            if(data.flag){
                self.gameHistory.gameHistoryData = data.flag;
                self.gameHistory.showLayer();
            }
        });
    },

    btnShowGameScoreList:function(){
        var self = this;
        pomelo.request("connector.entryHandler.sendData", {"code":"getScoreRecord","params":{}}, function(data) {
            console.log("获取自身积分记录");
            console.log(data);
            if(data.flag){
                self.gameScoreList.curHistoryData = data.flag;
                self.gameScoreList.showLayer();
            }
        });
    },

    btnShowGamePlayerList:function(){
        var self = this;
        pomelo.request("connector.entryHandler.sendData", {"code":"houseOwnerCmd","params":{code:"getUserMap"}}, function(data) {
            console.log("获取玩家列表");
            console.log(data);
            for(var i in data.flag.userMap)
                self.userHistoryList[parseInt(i)] = data.flag.userMap[i];
                
            self.gamePlayerList.curScoreData = data.flag.userScores;    
            self.gamePlayerList.curPlayerData = data.flag.userMap;
            self.gamePlayerList.showLayer();
        });
    },

    btnShowLookonList:function(){
        this.lookonList.curPlayerData = this.vistorList;
        this.lookonList.showLayer();
    },

    btnBetToOther:function(event, customEventData){
        var index = parseInt(customEventData);
        if(index == 0){
            this.showOrHideBetOther(0);
            return;
        }
        var self = this;
        pomelo.clientSend("bet",{"bet":this.readyBetNum,"chair":index},function(){
            console.log("readyBetNum!!!!!!");
        });
    },

    showOrHideBetOther:function(type){
        if(type)
        {
            for(var i in confige.roomPlayer)
                this.betOtherBtnList[i].active = true;
        }else{
            for(var i=0;i<9;i++)
                this.betOtherBtnList[i].active = false;
            this.curSelectBet = -1;
            for(var i=0;i<5;i++)
                this.betBtnList[i].node.y = 0;
        }
    },

    getDiamond:function(){
        var self = this;
        pomelo.request("connector.entryHandler.sendData", {"code":"houseOwnerCmd","params":{code:"getDiamond"}}, function(data) {
            console.log("getDiamond @@@@@@@@");
            console.log(data);
            self.addGameTimeLayer.showLayer(data.flag);
        });
    },

    getScoreType:function(str){
        if(str == "win")
            return -1;
        if(str == "lose")
            return 1;
        if(str == "tie")
            return 0;
    },

    initDiceNode:function(){
        console.log("initDiceNode??????????")
        this.diceNode = this.node.getChildByName("diceNode");
        this.diceAniNode = this.resNode.getChildByName("diceAniNode");
        this.diceAniList = {};
        for(var i=1;i<=6;i++)
        {
            this.diceAniList["R"+i] = this.diceAniNode.getChildByName("diceR"+i);
            this.diceAniList["W"+i] = this.diceAniNode.getChildByName("diceW"+i);
        }
        this.diceSprite1 = {};
        this.diceSprite2 = {};
    },

    showDiceAction:function(dice1,dice2){
        console.log("fuck showDiceAction!!!!!!");
        window.DKTools.audioEG.playEffect("tips_dice");
        var newDice1 = cc.instantiate(this.diceAniList["W"+dice1]);
        this.diceNode.addChild(newDice1);
        newDice1.x = 200;
        newDice1.y = 100;
        this.diceSprite1 = newDice1;

        var newDice2 = cc.instantiate(this.diceAniList["W"+dice2]);
        var callFunc1 = function(){
            this.diceNode.addChild(newDice2);
            newDice2.x = 200;
            newDice2.y = 50;
            this.diceSprite2 = newDice2;
            newDice2.getComponent("cc.Animation").play();
            newDice2.runAction(cc.moveBy(0.5,cc.p(-170+Math.random()*30,0+(Math.random()*60-30))));
        };
        this.scheduleOnce(callFunc1,0.1);
        

        newDice1.getComponent("cc.Animation").play();
        
        newDice1.runAction(cc.moveBy(0.5,cc.p(-230-Math.random()*30,-50+(Math.random()*60-30))));
        

        var callFunc2 = function(){
            newDice1.runAction(cc.moveTo(0.3,cc.p(-375,360)));
            newDice2.runAction(cc.moveTo(0.3,cc.p(-310,360)));
        };
        this.scheduleOnce(callFunc2,1.5);
    },

    showDiceActionOnReconnect:function(dice1,dice2){
        console.log("showDiceActionOnReconnect!!!!!!!!!!!!!")
        var newDice1 = cc.instantiate(this.diceAniList["R"+dice1]);
        this.diceNode.addChild(newDice1);
        this.diceSprite1 = newDice1;
        var newDice2 = cc.instantiate(this.diceAniList["W"+dice2]);
        this.diceNode.addChild(newDice2);
        this.diceSprite2 = newDice2;

        newDice1.x = -275;
        newDice1.y = 360;
        newDice2.x = -210;
        newDice2.y = 360;
    },

    cleanDice:function(){
        if(this.diceSprite1.destroy)
            this.diceSprite1.destroy();
        if(this.diceSprite2.destroy)
            this.diceSprite2.destroy();
    },

    resetSceneNew:function(){

    },

    updateMeScore:function(score){
        this.mainPlayerScore.string = Math.round(parseInt(score));
    },

    showSetKillNode:function(){
        console.log("showSetKillNode!!!!!!!!!!!!!")
        console.log("this.gameStart==="+this.gameStart)
        if(this.gameStart)
            return;
        this.setKillNode.active = true;
        this.setKillPoint.string = this.curKillPoint;
    },
    hideSetKillNode:function(){
        this.setKillNode.active = false;
    },
    setKillPointOKClick:function(){
        window.DKTools.audioEG.playEffect("tips_btnClick");
        var self = this;
        var newPoint = parseInt(this.setKillPoint.string);
        console.log("cur change kill point === "+newPoint);
        pomelo.request("connector.entryHandler.sendData", {"code":"houseOwnerCmd","params":{code:"setKillPoints",point:newPoint}}, function(data) {
            console.log("setKillPoints @@@@@@@@");
            console.log(data);
            if(data.flag)
                self.hideSetKillNode();
        });
    },
    changeKillPoints:function(newPoint){
        confige.roomData.killPoints = newPoint;
        if(this.isRoomBanker)
            this.curKillPoint = newPoint;
        this.gameInfoNode.roomInfo.getChildByName("killType").getComponent("cc.Label").string = newPoint+"点";
    },

    showSmallTips:function(str){
        if(this.smallTipsShow0 && !this.smallTipsShow1)
        {
            this.smallTips1.stopAllActions();
            this.smallTips1.opacity = 0;
            this.smallTips1Label.string = str;
            this.smallTips1.runAction(cc.sequence(cc.fadeIn(0.25),cc.delayTime(10),cc.fadeOut(0.35),cc.callFunc(function () {
                this.smallTipsShow1 = false;
            }, this)));
            this.smallTipsShow1 = true;
        }else{
            this.smallTips0.stopAllActions();
            this.smallTips0.opacity = 0;
            this.smallTips0Label.string = str;
            this.smallTips0.runAction(cc.sequence(cc.fadeIn(0.25),cc.delayTime(10),cc.fadeOut(0.35),cc.callFunc(function () {
                this.smallTipsShow1 = false;
            }, this)));
            this.smallTipsShow0 = true;
        }
    },

    hidePlayerBtn:function(){
        this.gameInfoNode.yuyinBtn.runAction(cc.fadeOut(0.5));
        this.gameInfoNode.btn_quickSay.runAction(cc.fadeOut(0.5));
        this.betBtnNode.runAction(cc.fadeOut(0.5));
        this.btnOpenCard.runAction(cc.fadeOut(0.5));
        this.btnMoveCard.runAction(cc.fadeOut(0.5));
        this.btnStandUp.runAction(cc.fadeOut(0.5));
    },
    showPlayerBtn:function(){
        this.gameInfoNode.yuyinBtn.runAction(cc.fadeIn(0.5));
        this.gameInfoNode.btn_quickSay.runAction(cc.fadeIn(0.5));
        this.betBtnNode.runAction(cc.fadeIn(0.5));
        this.btnOpenCard.runAction(cc.fadeIn(0.5));
        this.btnMoveCard.runAction(cc.fadeIn(0.5));
        this.btnStandUp.runAction(cc.fadeIn(0.5));
    },
});